Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Extract Foreign Key from Payload #60

Closed
wants to merge 3 commits into from

Conversation

cjmellor
Copy link
Owner

This PR aims to clean up some ways that the package handles things.

  1. Until now, if you created a Model that would be approved, e.g.
Comment::create(['body' => 'Hi']);

There would be a constraint violation when trying to approve the Model if it had a foreign key, i.e. a Comment model would normally have a relationship to a User model. Now, as long as the user adds the foreign key, everything should be okay, e.g.

Comment::create(['body' => 'Hi', 'user_id' => auth()->id()]);

If you were to add a comment via a relationship, e.g.

$user->comment()->create(['body' => 'Hi']);

there will be no difference, as this will always send the foreign key along with it.

  1. When creating a new Model (to be approved), and it had a relationship (like a user_id) then that property would be added to the new_data JSON payload, and I just didn't like how that looked, so I have extracted it to its own column in the approvals table. This does mean the user needs to run a new migration though when using the next version (should be v1.5.0)

…ately

fix: Add foreign id when creating a Model not via a relationship
docs: Updated documentation to explain how models with foreign ids work.
refactor: Renamed a method to avoid naming conflicts
docs: Added upgrade instructions
@cjmellor cjmellor self-assigned this Mar 18, 2024
@cjmellor cjmellor added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request labels Mar 18, 2024
@cjmellor cjmellor closed this Mar 18, 2024
@cjmellor cjmellor deleted the feat/extract-foreign-key branch March 18, 2024 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant